#include("/common/_layout.html")
#@layout()
#define layoutHead()
	<title>家长编辑</title>
#end
#define layoutBody()
	<body>
		<div class="page-content-wrap">
				<form class="layui-form" lay-filter="formedit">
					<input type="hidden" name="parent_id">
					<div class="layui-tab" style="margin: 0;">
						<ul class="layui-tab-title">
							<li><a id="a_goback_url" href="javascript:window.history.back();">家长列表</a></li>
							<li class="layui-this">家长编辑</li>
						</ul>
						<div class="layui-tab-content">
							<div class="layui-tab-item"></div>
							<div class="layui-tab-item layui-show">
								<div class="layui-form-item">
									<label class="layui-form-label">家长姓名：</label>
									<div class="layui-input-block">
										<input type="text" name="parent_name" required lay-verify="required" placeholder="请输入家长姓名" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">手机：</label>
									<div class="layui-input-block">
										<input type="text" name="parent_mobile" required lay-verify="phone" placeholder="请输入手机" autocomplete="off" class="layui-input">
										<div style="font-size:12px;color:#404040;margin:5px;">注：手机号默认为【登录账户】，请输入真实有效的手机号，创建后不可更改</div>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">用户密码：</label>
									<div class="layui-input-block">
										<input type="password" name="user_pwd" placeholder="不修改，请置空" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">班级：</label>
									<div class="layui-input-block">
										<select id="class_id" name="class_id" lay-verify="required" lay-filter="class_id">
											<option value="">请选择班级</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">学生：</label>
									<div class="layui-input-block">
										<select id="student_id" name="student_id" lay-verify="required">
											<option value="">请选择学生</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">亲属关系：</label>
									<div class="layui-input-block">
										<select id="kindred_id" name="kindred_id" lay-verify="required">
											<option value="">请选择亲属关系</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">状态：</label>
									<div class="layui-input-block">
										<select name="parent_state" lay-verify="required">
											<option value="1">启用</option>
											<option value="0">禁用</option>
										</select>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item" style="padding-left: 10px;">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即提交</button>
						</div>
					</div>
				</form>
		</div>
		<script src="/static/js/jquery.formHelp.js" type="text/javascript" charset="utf-8"></script>
		<script>
			
			layui.use(['form', 'layer', 'laytpl', 'element', 'laydate'], function() {
				var form = layui.form();
				var layer = layui.layer;
				var laytpl = layui.laytpl,
					element = layui.element(),
					laydate = layui.laydate;
					
				
				// 表单验证
				form.verify({
				});

				//监听提交
				form.on('submit(formDemo)', function(formData){
					sendPost("/api/eduorg/parent/save", formData.field, function(res) {
						layer.alert(res.msg, {
							title: '信息提示'
						}, function(idx){
							if (res.code==200){
								window.history.back();;
							}
							layer.close(idx);
						});
					});
					return false;
				});
				
				form.on('select(class_id)', function(data){
					$('#student_id').html('<option value="">请选择学生</option>');
					form.render('select');
					var sval = data.value;
					if (sval != null && sval != "undefined" && sval != "" && sval > 0){
						sendPost("/api/eduorg/student/getStudents", {class_id: sval}, function(res) {
							if (res.hasOwnProperty("liststudent")) {
								bindSelectJSONProps("student_id", res, "liststudent", "student_name", "student_id", "");
								form.render('select');
							}
						});
					}
				});  

				// 页面初始化
				function page_init(){
					var id = getUrlParam('id');
					if (id===null || id === 'undefined' || id<=0){
						$("[name='user_pwd']").attr("lay-verify","passwd").attr("placeholder","请输入密码");
					}
					// 加载初始化编辑数据
					sendGet("/api/eduorg/parent/getOne", {
						id : getUrlParam("id")
					}, function(res) {
						//console.log(res);
						if (res.hasOwnProperty("listkindred")) {
							bindSelectJSONProps("kindred_id", res, "listkindred", "kindred_name", "kindred_id", "");
						}
						if (res.hasOwnProperty("listclass")) {
							bindSelectJSONProps("class_id", res, "listclass", "class_name", "class_id", "");
						}
						if (res.hasOwnProperty("liststudent")) {
							bindSelectJSONProps("student_id", res, "liststudent", "student_name", "student_id", "");
						}
						// 初始化编辑数据
						if (res.hasOwnProperty("oneinfo")) {
							$("form.layui-form").setForm(res.oneinfo);
						}
						form.render();
					});
				}
				page_init();
			});
			
			
					
		</script>
	</body>

#end